home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Boxer / MacUnBoxer / SimpleAlert.c < prev   
C/C++ Source or Header  |  2000-06-23  |  2KB  |  120 lines

  1. /*
  2.  *  C Toolbox Stationery
  3.  *  by Josef W. Wankerl
  4.  *  04/11/00
  5.  */
  6.  
  7. #include <Dialogs.h>
  8. #include <Fonts.h>
  9. #include <MacWindows.h>
  10. #include <Menus.h>
  11. #include <QuickDraw.h>
  12. #include <TextEdit.h>
  13. #include <string.h>
  14. #include <stdio.h>
  15.  
  16. enum
  17. {
  18.     kAlertID = 128
  19. };
  20.  
  21. static void Initialize(void)
  22. {
  23.     InitGraf(&qd.thePort);
  24.     InitFonts();
  25.     InitWindows();
  26.     InitMenus();
  27.     TEInit();
  28.     InitDialogs(nil);
  29.     InitCursor();
  30. }
  31.     StandardFileReply reply;
  32.  
  33. #define htonl(x) x
  34. #define htons(x) x
  35.  
  36. struct prchead {
  37.   char name[32];                //0-32
  38.   short int attr;               //32-33
  39.   short int vers;               //34-35
  40.   long int cr, md, bkt;         //times 36-47
  41.   long int mn, app, sort;       // zero 48-59 - zero for prcs.
  42.   long int type, crea;          //60-67
  43.   long int uidseed, nxrec;      //68-75 - uidseed rand, nxrec zero;
  44.   short int nrecs;              //76-78
  45. } head;
  46.  
  47. #define title argv[1]
  48. void main(void)
  49. {
  50.  
  51.  
  52.   unsigned long cofst;
  53.  char bbuf[5000], nbuf[32];
  54.   unsigned short xshort;
  55.   unsigned long xlong, xid,xlong2;
  56.   long bbuflen;
  57.   int  maxsect,i;
  58.   char argv[2][80];
  59.   FILE *outfd, *infd;
  60.   
  61.       Initialize();
  62.     
  63. StandardGetFile(NULL,0,NULL,&reply);
  64.  
  65. strcpy(argv[1],(char *) reply.sfFile.name);
  66. {
  67. infd = fopen(argv[1],"r");
  68.  
  69.     fread(&head, 1,sizeof(head),infd);
  70.     fread(&xlong, 1,4,infd);
  71.  
  72.     maxsect = htons(head.nrecs);
  73.  
  74.     cofst = htonl(xlong);
  75.  
  76.  
  77.  
  78.     if (!strcmp(&title[strlen(title) - 4], ".pdb"))
  79.       title[strlen(title) - 4] = 0;
  80.     else
  81.       strcat(title, ".out");
  82.  
  83.     outfd = fopen(title, "w");
  84.  
  85.     for (i = 0; i < maxsect; i++) {
  86.  
  87.       fread( title, 1,4,infd);
  88.  
  89.       if (i + 1 != maxsect) {
  90.  
  91.         fread( &xlong2,1, 4,infd);
  92.  
  93.         bbuflen = htonl(xlong2);
  94.         bbuflen = bbuflen - cofst;
  95.       } else
  96.         bbuflen = 4096 + 8;
  97.  
  98.       if (bbuflen > 8400 || bbuflen < 8)
  99.         exit(-3);
  100.  
  101.       xlong = fseek(infd, 0, SEEK_CUR);
  102.       fseek(infd, cofst, SEEK_SET);
  103.  
  104.       fread(bbuf, 1,4,infd);
  105.       if (strncmp(bbuf, "DBLK", 4))
  106.         exit(-2);
  107.       fread( &cofst, 1,4,infd);
  108.       bbuflen -= 8;
  109.       bbuflen = fread(bbuf, 1,bbuflen,infd);
  110.  
  111.       fseek(infd, xlong, SEEK_SET);
  112.       cofst = htonl(xlong2);
  113.     fwrite( bbuf, 1,bbuflen,outfd);
  114.  
  115.     }
  116.  
  117.     fclose(outfd);
  118.         fclose(infd);
  119.   }
  120. }